package com.xmtlxx.common.mqtt;

import lombok.Getter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * @author RonyChan
 * @since 2022/6/24 17:32
 */
@Component
@ConfigurationProperties(prefix = "mqtt")
public class MqttConfiguration {
    @Getter
    private static String host;
    @Getter
    private static String userName;
    @Getter
    private static String password;
    @Getter
    private static String clientId;
    @Getter
    private static int timeOut;
    @Getter
    private static int keepAlive;
    @Getter
    private static String topic;

    public void setHost(String host) {
        MqttConfiguration.host = host;
    }

    public void setUserName(String userName) {
        MqttConfiguration.userName = userName;
    }

    public void setPassword(String password) {
        MqttConfiguration.password = password;
    }

    public void setClientId(String clientId) {
        MqttConfiguration.clientId = clientId;
    }

    public void setTimeOut(int timeOut) {
        MqttConfiguration.timeOut = timeOut;
    }

    public void setKeepAlive(int keepAlive) {
        MqttConfiguration.keepAlive = keepAlive;
    }

    public void setTopic(String topic) {
        MqttConfiguration.topic = topic;
    }

//    @Bean//注入spring
//    public TLMQTTClient tlMQTTClient() {
//        TLMQTTClient tlMQTTClient = new TLMQTTClient(host, userName, password, clientId, timeOut, keepAlive);
//        for (int i = 0; i < 10; i++) {
//            try {
//                System.out.println("MQTT connect");
//                tlMQTTClient.connect();
//                tlMQTTClient.subscribe(topic, 0);
//                return tlMQTTClient;
//            } catch (MqttException e) {
//                System.out.println("MQTT connect exception,connect time = " + i);
//                e.printStackTrace();
//                try {
//                    Thread.sleep(2000);
//                } catch (InterruptedException e1) {
//                    e1.printStackTrace();
//                }
//            }
//        }
//        return tlMQTTClient;
//    }

}
